#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int w[maxn], sum, n;
int dp[maxn];
vector<int> g[maxn];
void addedge(int f, int t) { g[f].push_back(t), g[t].push_back(f); }
void dfs(int fa, int no)
{
    int mx = 0;
    for (int i = 0; i < g[no].size(); ++i)
    {
        if (fa == g[no][i])
            continue;
        dfs(no, g[no][i]);
        mx = max(mx, dp[g[no][i]]);
    }
    dp[no] = mx + w[no];
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for (int i = 1; i < n; ++i)
    {
        int f, t, v;
        cin >> f >> t >> v;
        w[t] = v;
        addedge(f, t);
        sum += w[t];
    }
    dfs(0, 1);
    cout << sum - dp[1] << endl;
}
